{
数据结构 解题报告：
http://git.oschina.net/et0662/sznoi-Data_Structure
}


type 
	pnode=^node;
	node = record
		ch:char;
		next:pnode;
		end;
	Stack=^node;

{return c1>c2}
function operationCMP(c1,c2:char):boolean;
begin
	if((c2='+') or (c2='-')) and ((c1='*') or (c1='/')) then
		operationCMP:=true
	else
		operationCMP:=false;
end;

procedure push(s:Stack; ch:char);
var
	p:pnode;
begin
	if(s^.next=nil)then
	begin
		new(p);
		p^.next:=nil;
		p^.ch:=ch;
		s^.next:=p;
	end
	else
	begin
		new(p);
		p^.next:=s^.next;
		p^.ch:=ch;
		s^.next:=p;
	end;
end;

function pop(s:Stack):char;
var
	p:pnode;
	ch:char;
begin
	if(s^.next=nil)then
		pop:=chr(0)
	else
	begin
		p:=s^.next;
		s^.next:=p^.next;
		ch:=p^.ch;
		dispose(p);
		pop:=ch;
	end;
end;

var
	s:Stack;
	ch:char;
begin
	new(s);
	s^.next:=nil;
	while(not eoln) do
	begin
		read(ch);
		{操作数就直接输出}
		if (ord('0')<=ord(ch)) and (ord(ch)<=ord('9'))then
			write(ch,' ')
		else if(s^.next=nil) then
			push(s,ch)
		else if(ch='(')then
			push(s,ch)
		else if(ch=')') then begin
			ch:=pop(s);
			while(ch<>'(')do
			begin
				write(ch,' ');
				ch:=pop(s);
			end;
			end
		else begin
			if(s^.next^.ch='(') then
				push(s,ch)
			else begin
				{输入的操作符不高于，栈内运算符，就依次弹出}
				while((s^.next<>nil) and (not operationCMP(ch,s^.next^.ch))) do
				begin
					write(pop(s),' ');
				end;
				push(s,ch);
			end;
		end;
	end;
	while(s^.next<>nil)do
		write(pop(s),' ');
end.
